home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 090 / yase.arc / EDIT2.ASM < prev    next >
Assembly Source File  |  1986-12-13  |  7KB  |  198 lines

  1. ******************************************************************
  2. * COPYRIGHT (C) 1986 by Donald Krantz and James Stanley
  3. * - Note: This is a real, live, actual, registered copyright,
  4. *   and should be treated as such. This source code is from
  5. *   the book "68000 Assembly Language", Krantz and Stanley,
  6. *   Addison-Wesley Publishing Company, Reading, MA, 1986.
  7. *   Permission granted by the authors for non-commercial use
  8. *   in programs released to the public domain, as long as this
  9. *   copyright notice remains attached and visible.
  10. *
  11. *****************************************************************
  12. * EDIT2 - Screen printer. Updates the display after each cursor
  13. *  move or file modification.
  14.  
  15.     xref    cursor,putc,printf
  16.     xdef    prtscr,exp_chr,stats,set_edit,cmd_w
  17.  
  18. #edit.h
  19.  
  20. *****************************************************************
  21. * PRTSCR - Prints screen from A5
  22. prtscr:
  23.     movem.l    d1-d5/a0,-(a7)
  24. redo:
  25.     move.l    top_lef(a5),a0    * get starting character for scrn
  26.     move.w    w_ulcy(a5),d3    * d3 is screen row number
  27. row_loop:
  28.     move.w    w_ulcx(a5),d2    * d2 is screen column number
  29.     clr.w    d5        * D5 is logical column
  30.     clr.w    d4        * D4 is actual column in line
  31.     move.w    d3,-(a7)      * Push cursor Y base location
  32.     move.w    d2,-(a7)      * Push cursor X base address
  33.     bsr    cursor        * setup cursor location
  34.     addq.l    #4,a7        * adjust stack
  35. chr_loop:
  36.     cmp.l    b_gap(a5),a0    * Test for gap
  37.     blt    sk1_ps        * Not at gap, jump by
  38.     cmp.l    e_gap(a5),a0    * Are we already past gap?
  39.     bge    sk1_ps        * Yes, jump by
  40.     move.l    e_gap(a5),a0    * move pointer past gap
  41.     move.w    d2,scr_col(a5)    * save cursor position
  42.     move.w    d3,scr_row(a5)    
  43.     move.w    d5,log_col(a5)    * Save logical column
  44.     cmp.w    w_off(a5),d4    * are we before window edge?
  45.     bge    sk2_ps        * nope.
  46.     clr.w    w_off(a5)    * set offset to zero, redraw
  47.     bra    redo
  48. sk2_ps:
  49.     cmp.w    w_lrcx(a5),d2    * are we past window edge?
  50.     ble    sk1_ps        * no, continue
  51.     sub.w    w_lrcx(a5),d4    * subtract difference
  52.     add.w    w_ulcx(a5),d4    * add screen offset
  53.     addq.w    #8,d4        * add eight for good measure
  54.     add.w    d4,w_off(a5)    * set window offset, redraw
  55.     bra    redo
  56. sk1_ps:
  57.     cmp.l    e_buf(a5),a0    * Test for end of file
  58.     bgt    sk0_ps        * jump on end of file
  59.     move.b    (a0)+,d0    * pick up printable character
  60.     cmp.b    #10,d0        * is this a newline?
  61.     beq    sk0_ps        * if yes, line is complete
  62.     bsr    exp_chr        * expand character and print
  63.     bra    chr_loop    * get next char and repeat
  64. sk0_ps:
  65.     bsr    clr_eol        * Clear to end of line
  66. row_tst:
  67.     addq.w    #1,d3        * Increment row
  68.     cmp.w    w_lrby(a5),d3    * enough lines to fill window?
  69.     blt    row_loop    * jump back if not.
  70.     move.w    scr_row(a5),-(a7) reset cursor to proper location
  71.     move.w    scr_col(a5),-(a7)
  72.     bsr    cursor        * go set cursor
  73.     addq.l    #4,a7        * adjust stack
  74.     movem.l    (a7)+,d1-d5/a0
  75.     rts
  76. *****************************************************************
  77. * EXP_CHR - expands and prints a character
  78. *  D0.B    is character to print
  79. *  D5.W is logical screen column, in/out parameter
  80. *  D4.W is column count into line, in/out parameter
  81. *  D2.W is actual screen X position, in/out parameter
  82. exp_chr:
  83.     cmp.b    #$9,d0        * Is this a tab character?
  84.     beq    tabs        * If so, expand tabs.
  85.     cmp.b    #$20,d0        * is this a control char?
  86.     blt    control        * If so, expand control char
  87.     cmp.w    w_off(a5),d4    * are we up to window edge?
  88.     blt    sk0_ex        * no, skip the printing.
  89.     cmp.w    w_lrcx(a5),d2    * are we past window edge?
  90.     bgt    sk0_ex        * if so, skip printing
  91.     move.w    d0,-(a7)    * just print regular chars
  92.     bsr    putc
  93.     addq.l    #2,a7        * adjust stack    
  94.     addq.l    #1,d2        * add 1 to screen column
  95. sk0_ex:
  96.     addq.l    #1,d5        * add 1 to logical column
  97.     addq.l    #1,d4        * add 1 to line's column count
  98.     bra    exp_exit    * processing complete
  99. tabs:
  100.     move.b    #' ',d0        * expand with spaces
  101.     bsr    exp_chr        * call recursively
  102.     move.w    d5,d1        * get copy of logical column
  103.     and.w    #7,d1        * check for tab column stop
  104.     bne    tabs        * repeat as necessary
  105.     bra    exp_exit    * leave when done
  106. control:
  107.     move.w    d0,-(a7)    * save character
  108.     move.b    #'^',d0        * pass a circumflex recursively
  109.     bsr    exp_chr        * go do it
  110.     move.w    (a7)+,d0    * retrieve character
  111.     add.b    #$40,d0        * make it printable
  112.     bsr    exp_chr        * print it out
  113.     subq.w    #2,d5        * adjust logical column
  114. exp_exit:
  115.     rts
  116. *****************************************************************
  117. * CLR_EOL - Clears to end of line
  118. *   D2.W is actual screen column
  119. clr_eol:
  120.     move.w    #'  ',-(a7)    * push spaces
  121. lp0_el:
  122.     cmp.w    w_lrcx(a5),d2    * test if we're at end of window
  123.     bgt    sk0_el        * if so, we're done
  124.     bsr    putc        * otherwise, print blank
  125.     addq.w    #1,d2        * adjust screen position
  126.     bra    lp0_el        * and repeat
  127. sk0_el:
  128.     addq.l    #2,a7        * adjust stack (remove blank)
  129.     rts
  130. *****************************************************************
  131. * STATS - prints current file stats in command window
  132. stats:
  133.     movem.l    d0/d1/a5,-(a7)
  134.     tst.w    insert(a5)      * check if insert on or off
  135.     beq    no_ins
  136.     move.l    #on,-(a7)      * push "On" message
  137.     bra    past_ins
  138. no_ins:
  139.     move.l    #off,-(a7)      * push "Off" message
  140. past_ins:
  141.     move.l    e_gap(a5),d0      * compute space available
  142.     sub.l    b_gap(a5),d0
  143.     move.w    d0,-(a7)
  144.     move.l    b_gap(a5),d0      * compute chars behind cursor
  145.     sub.l    b_buf(a5),d0
  146.     move.w    d0,-(a7)
  147.     move.w    log_col(a5),-(a7) * print logical column
  148.     move.w    log_lin(a5),-(a7) * print logical line
  149.     pea    fname(a5)      * print filename
  150.     move.l    #cmd_w,a5      * load up command window desc.
  151.     move.w    w_ulcy(a5),-(a7)  * push Y position
  152.     add.w    #1,(a7)          * adjust Y position
  153.     move.w    w_ulcx(a5),-(a7)  * push X position
  154.     move.l    #statstr,-(a7)      * push format string address
  155.     bsr    printf
  156.     add.l    #24,a7          * adjust stack
  157.     movem.l    (a7)+,d0/d1/a5
  158.     rts
  159. statstr:
  160.     dc.b    '%vFile: %-14s LN %-5u CO %-5u CH %-5u SP %-5u'
  161.     dc.b    ' Insert %-3s',0    
  162. on:    dc.b    'On',0
  163. off:    dc.b    'Off',0
  164.     dc.w    0
  165. *****************************************************************
  166. * SET_EDIT - initializes edit descriptor file parameters
  167. set_edit:
  168.     move.l    a0,-(a7)    * save caller's a0
  169.     clr.w    scr_row(a5)    * cursor Y address
  170.     clr.w    scr_col(a5)    * cursor X address
  171.     clr.w    ed_err(a5)    * edit error flag
  172.     clr.w    modify(a5)    * file modified flag
  173.     move.l    a5,a0        * descriptor base address
  174.     add.l    #buffer,a0    * offset to start of char buffer
  175.     move.l    a0,b_buf(a5)    * buffer start address
  176.     move.l    a0,b_gap(a5)    * gap starting address
  177.     move.l    a0,top_lef(a5)    * addr of top left character
  178.     move.l    a5,a0        * descriptor base address
  179.     add.l    #DESC-1,a0    * add offset to end of buffer
  180.     move.l    a0,e_buf(a5)    * buffer end address
  181.     addq.l    #1,a0        * gap end address
  182.     move.l    a0,e_gap(a5)    * gap ending address
  183.     clr.l    blk_st(a5)    * block start address
  184.     clr.l    blk_end(a5)    * block end address
  185.     clr.l    cur_lin(a5)    * address 1st char, current line
  186.     clr.w    log_lin(a5)    * cursor logical line
  187.     clr.w    log_col(a5)    * cursor logical column
  188.     clr.w    w_off(a5)    * set offset to 0
  189.     move.w    #$FFFF,insert(a5) turn insert toggle on
  190.     move.l    (a7)+,a0    * restore caller's a0
  191.     rts
  192. *****************************************************************
  193.     bss
  194. cmd_w:    ds.b    buffer        * command I/O window
  195.  
  196.     end
  197.